<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card class="box-card">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" class="input-with-select" clearable>
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="orders" stripe border>
        <el-table-column type="index" label="*"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status === '0'" type="danger">未付款</el-tag>
            <el-tag v-else type="success">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">{{scope.row.create_time | formatData}}</template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <template>
            <!-- 修改 -->
            <el-button @click="showBox" type="primary" icon="el-icon-edit" size="mini"></el-button>
            <!-- 查询 -->
            <el-button @click="showProgress" type="success" icon="el-icon-location" size="mini"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryData.pagenum"
        :page-sizes="[2, 4, 6, 10]"
        :page-size="queryData.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog @close="addressDialogClose" title="修改地址" :visible.sync="addressVisible" width="50%">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
        <el-form-item label="省市区/县" prop="address">
          <el-cascader v-model="ruleForm.address" :options="cityData"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="infoAddress">
          <el-input v-model="ruleForm.infoAddress"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog title="修改地址" :visible.sync="progressVisible" width="50%">
      <el-timeline :reverse="true">
        <el-timeline-item
          v-for="(activity, index) in progressDialogVisible"
          :key="index"
          :timestamp="activity.ftime"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="progressVisible = false">取 消</el-button>
        <el-button type="primary" @click="progressVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data () {
    return {
      queryData: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orders: [],
      total: 0,
      addressVisible: false,
      ruleForm: {
        address: [],
        infoAddress: ''
      },
      rules: {
        address: [
          { required: true, message: '请选择省市区/县', trigger: 'blur' }
        ],
        infoAddress: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      cityData: cityData,
      progressVisible: false,
      progressDialogVisible: []
    }
  },

  created () {
    this.getOrdersList()
  },

  methods: {
    async getOrdersList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryData
      })
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.orders = res.data.goods
      this.total = res.data.total
    },
    // 每页展示几条数据
    handleSizeChange (newData) {
      this.queryData.pagesize = newData
      this.getOrdersList()
    },
    // 跳转页码
    handleCurrentChange (val) {
      this.queryData.pagenum = val
      this.getOrdersList()
    },
    showBox () {
      this.addressVisible = true
    },
    addressDialogClose () {
      this.$refs.ruleForm.resetFields()
    },
    async showProgress () {
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      this.progressDialogVisible = res.data
      this.progressVisible = true
    }
  }
}
</script>

<style scoped lang='less'>
.el-table {
  margin-top: 10px;
}
.el-cascader {
  width: 100%;
}
</style>
